<?php
/**
 * Created by PhpStorm.
 * User: jason
 * Date: 2018/12/28
 * Time: 23:39
 */

namespace App\Services;

use App\Models\User;

class UserService
{
    public function getGenderProportion()
    {
        $userGender = User::query()->selectRaw('count(*) as count, gender')
            ->groupBy('gender')
            ->get();

        $genders = [];
        foreach ($userGender as $item) {
            $genders[] = [
                'name' => $item['gender'],
                'value' => $item['count'],
            ];
        }
        return $genders;
    }
}